import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[][] input = new int[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                input[i][j] = sc.nextInt();
            }
        }
        int NK = N * K; //4
        for (int i = 0; i < NK; i++) {
            for (int j = 0; j < NK; j++) {
                int curRow = (i == 0 ? 0 : i / K);
                int curCol = (j == 0 ? 0 : j / K);
                if (j < NK - 1) {
                    System.out.print(input[curRow][curCol] + " ");
                } else {
                    System.out.print(input[curRow][curCol]);
                }
            }
            if (i < NK) {
                System.out.println();
            }
        }
    }
}